export default {
  methods: {
    convertEvents() {
      // 转换events，兼容老的普通事件
      const { events } = this.config;
      const { tableData } = this.config.config.data;
      if (events && events.length) {
        const event = events.find(item => item.type === 'out');
        const col = tableData.find(t => String(t.mapping) === String(event.paramKey));
        if (col && event && event.parameters) {
          const match = event.parameters[0].value.match(/^\{(.*)\}$/);
          if (!match) {
            event.parameters[0].value = `{${col.field}}`;
          }
          event.parameters.forEach(item => {
            item.id = '';
          });
        }
      }

      if (this.orgConfig && this.orgConfig.events && this.orgConfig.events.length) {
        const orgEvents = this.orgConfig.events;
        const orgEvent = orgEvents.find(item => item.type === 'out');
        if (orgEvent && orgEvent.parameters) {
          orgEvent.parameters = orgEvent.parameters.filter(item => item?.key.includes('emit_params_obj'));
        }
      }
    },
  },
};
